package com.fenxiangtech.mall.manager;

import com.fenxiangtech.mall.dao.AreaDAO;
import com.fenxiangtech.mall.model.Area;
import com.fenxiangtech.mall.model.qc.AreaQC;
import com.fenxiangtech.mall.model.qc.Page;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

@Component
public class AreaManager {

    @Autowired
    private AreaDAO areaDAO;

    public List<Area> queryArea(Area area, Integer pageIndex , Integer pageSize){
        Page page = new Page(pageIndex,pageSize);
        AreaQC qc  = new AreaQC();
        qc.setPage(page);
        BeanUtils.copyProperties(area,qc);
        List<Area> areas = areaDAO.listArea(qc);
        return areas;
    }

    public Long countArea(Area area){
        AreaQC qc  = new AreaQC();
        BeanUtils.copyProperties(area,qc);
        Long count = areaDAO.countArea(qc);
        return count;
    }

    public int saveArea(Area area){

        if(area.getId()!=null){
            return areaDAO.updateArea(area);
        }else {
            area.setCreateTime(new Date());
            return areaDAO.insertArea(area);
        }

    }
    public int deleteArea(Long id){

        return areaDAO.deleteAreaById(id);

    }



}
